import Page
from Page import Xting
from Base.Base import Base
from selenium.webdriver.common.by import By


class XtingIndexPage(Base):
    """
    想听-首页页面
    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 搜索按钮
        self.index_search_btn = (By.XPATH, Xting.RESOURCE_ID.format("tv_search"))

        # 推荐标题
        self.index_recommendation_btn = (By.XPATH, Page.TEXT.format("推荐"))

        # 排行榜标题
        self.index_rank_btn = (By.XPATH, Page.TEXT.format("排行榜"))

        # 分类标题
        self.index_category_btn = (By.XPATH, Page.TEXT.format("分类"))

        # 奔腾电台
        self.index_benteng_radio_btn = (By.XPATH, Page.TEXT.format("奔腾电台"))

        # 本地电台
        self.index_local_radio_btn = (By.XPATH, Page.TEXT.format("本地电台"))

        # 我的电台
        self.index_my_radio_btn = (By.XPATH, Page.TEXT.format("我的电台"))

        # 音乐列表标题, 默认选择第1个, 取值范围[1,5]
        self.index_list_radio_title_text = (By.XPATH, Xting.index_list_radio_title_text.format(1))

        # 音乐列表封面, 默认选择第1个, 取值范围[1,5]
        self.index_list_radio_cover_img = (By.XPATH, Xting.index_list_radio_cover_img.format(1))

        # 缩略播放器播放icon
        # 因开发未区分icon与封面,故封面与icon可视为一体
        # self.index_thumb_play_icon = (By.XPATH, Xting.RESOURCE_ID.format("ib_control"))

        # 缩略播放器封面
        self.index_thumb_cover_img = (By.XPATH, Xting.RESOURCE_ID.format("ib_control"))

        # 缩略播放器歌名
        self.index_thumb_info_text = (By.XPATH, Xting.RESOURCE_ID.format("tv_name"))

        # 滑动条
        self.index_scroll_bar = (By.XPATH, Xting.RESOURCE_ID.format("scroll_bar"))

    def get_recommendation(self):
        """
        获取推荐tab
        :return:
        """
        return self.find_element_o(self.index_recommendation_btn)

    def get_rank(self):
        """
        获取分类tab

        :return:
        """
        return self.find_element_o(self.index_rank_btn)

    def get_benteng_radio(self):
        """
        返回侧边栏的奔腾电台

        :return:
        """
        return self.find_element_o(self.index_benteng_radio_btn)

    def get_list_radio_title(self, index=1):
        """
        根据索引获取列表电台的标题对象

        :param index: 列表音乐的索引, 从1开始计数
        :return: 列表音乐的标题对象
        """

        self.index_list_radio_title_text = (By.XPATH, Xting.index_list_radio_title_text.format(index))

        return self.find_element_o(self.index_list_radio_title_text)

    def get_list_radio_cover(self, index=1):
        """
        根据索引获取列表电台的封面对象

        :param index: 列表音乐的索引, 从1开始计数
        :return: 列表音乐的封面对象
        """
        self.index_list_radio_cover_img = (By.XPATH, Xting.index_list_radio_cover_img.format(index))

        return self.find_element_o(self.index_list_radio_cover_img)

    def get_thumb_info(self):
        """
        获取缩略播放器标题元素

        :return:
        """
        return self.find_element_o(self.index_thumb_info_text)

    def get_thumb_icon(self):
        """
        返回缩略播放器icon元素

        :return:
        """
        return self.find_element_o(self.index_thumb_cover_img)

    # def get_network_retry(self):
    #     """
    #     获取重新加载按钮
    #
    #     :return:
    #     """
    #     self.find_element_o(Page.index_network_retry_btn)

    def click_rank(self):
        """
        点击排行榜tab

        :return: None
        """
        self.click_element(self.index_rank_btn)

    def click_category(self):
        """
        点击分类tab

        :return: None
        """
        self.click_element(self.index_category_btn)

    def click_search(self):
        """
        点击搜索按钮

        :return: None
        """
        self.click_element(self.index_search_btn)

    def click_local_radio(self):
        """
        点击侧边栏的 `本地电台`

        :return:
        """
        self.click_element(self.index_local_radio_btn)

    def click_my_radio(self):
        """
        点击侧边栏的 `我的电台`

        :return:
        """
        self.click_element(self.index_my_radio_btn)

    def click_list_radio(self, index):
        """
        点击指定索引的列表电台

        :param index: 列表索引, 从1开始计数, 取值范围[1, 5]
        :return: None
        """
        self.index_list_radio_cover_img = (By.XPATH, Xting.index_list_radio_cover_img.format(index))
        self.click_element(self.index_list_radio_cover_img)

    def click_thumb_info(self):
        """
        点击缩率播放器的标题

        :return: None
        """
        self.click_element(self.index_thumb_info_text)

    def click_thumb_icon(self):
        """
        点击缩略播放器的icon

        :return: None
        """
        self.click_element(self.index_thumb_cover_img)

    def is_display_benteng_radio(self):
        """
        是否展示奔腾电台的tab

        :return: bool
        """
        return self.is_display(self.index_benteng_radio_btn)


if __name__ == '__main__':
    pass
